import rxAjax from '@/assets/js/ajax.js';
import FormUtil from "@/assets/js/form-util";

//大屏的视图管理 api接口
export const ScreenViewManageApi = {};

ScreenViewManageApi.baseUrl = '/api-screen/screen/core/screenViewManage';
ScreenViewManageApi.exportUrl = ScreenViewManageApi.baseUrl + '/listExport';
ScreenViewManageApi.treeBaseUrl= '/api-system/system/core/sysTree';
ScreenViewManageApi.permissionUrl= '/api-screen/screen/core/screenPermission';

//查询列表
ScreenViewManageApi.query = function (parameter) {
	let url = ScreenViewManageApi.baseUrl + '/query';
	return rxAjax.postJson(url, parameter).then(res => {
		return res.result
	})
}

/**
 * 获取单记录
 * @param pkId
 * @returns {*}
 */
ScreenViewManageApi.get = function (pkId) {
	let url = ScreenViewManageApi.baseUrl + '/get?pkId=' + pkId;
	return rxAjax.get(url);
}

//保存数据
ScreenViewManageApi.save = function (parameter) {
	let url = ScreenViewManageApi.baseUrl + '/save';
	return rxAjax.postJson(url, parameter);
}

//删除数据
ScreenViewManageApi.del = function (parameter) {
	let url = ScreenViewManageApi.baseUrl + '/del';
	return rxAjax.postUrl(url, parameter);
}

//根据别名获取大屏
ScreenViewManageApi.getByAlias = function (alias,appId,isAuth) {
	let url = ScreenViewManageApi.baseUrl + '/getByAlias?alias=' + alias;
	if(appId){
		url+="&appId="+appId;
	}
	if(isAuth!=undefined){
		url+="&isAuth="+isAuth;
	}
	return rxAjax.get(url);
}

//根据分享链接获取大屏
ScreenViewManageApi.getByLinkShare = function (alias,appId,password) {
	let parameter={
		alias:alias,
		appId:appId,
		password:password,
	}
	let url = ScreenViewManageApi.baseUrl+"/getByLinkShare";
	return rxAjax.postUrl(url,parameter);
}

//获取天气
ScreenViewManageApi.getWeather = function (cityId) {
	let url = ScreenViewManageApi.baseUrl + '/getWeather?cityId='+cityId;
	return rxAjax.get(url);
}

//获取图表数据
ScreenViewManageApi.getData =function(config) {
	let url=ScreenViewManageApi.baseUrl +'/getData';
	return rxAjax.postJson(url,config);
}

//导入
ScreenViewManageApi.importScreen =function(formData,treeId) {
	let url=ScreenViewManageApi.baseUrl +'/importScreen?treeId='+treeId;
	return rxAjax.upload(url,formData);
}

//通过应用ID查找应用，如果应用ID为空则显示系统内置的应用
ScreenViewManageApi.getAppById=function (appId) {
    var url='/api-system/system/core/sysApp/getById?appId=' + appId;
    return rxAjax.get(url);
}

//根据应用获取菜单
ScreenViewManageApi.getAllSysMenuListByAppId= function(parameter) {
	var url='/api-system/system/core/sysMenu/getMenusByAppId';
	let data = rxAjax.get(url,parameter);
	return data;
}

//保存菜单
ScreenViewManageApi.saveSysMenu= function(parameter) {
  var url='/api-system/system/core/sysMenu/save';
  return rxAjax.postJson(url,parameter);
}
ScreenViewManageApi.getById = function (pkId) {
	var url = ScreenViewManageApi.baseUrl + '/getById?pkId=' + pkId;
	return rxAjax.get(url);
}
ScreenViewManageApi.treeGet =function(pkId) {
	var url= ScreenViewManageApi.treeBaseUrl + '/get?pkId=' + pkId;
	return rxAjax.get(url);
}

ScreenViewManageApi.treeSave =function(parameter) {
	var url= ScreenViewManageApi.treeBaseUrl + '/save';
	return rxAjax.postJson(url,parameter);
}
ScreenViewManageApi.delByTreeId =function(parameter) {
	var url = ScreenViewManageApi.treeBaseUrl + '/delByTreeId';
	return rxAjax.postUrl(url, parameter);
}

//导出多个大屏
ScreenViewManageApi.exportScreenByIds =function(data) {
	let url=ScreenViewManageApi.baseUrl +'/exportScreenByIds';
	return FormUtil.doExport(url,data);
}

//保存大屏分享与授权
ScreenViewManageApi.savePermissionAndShare =function(parameter) {
	let url=ScreenViewManageApi.baseUrl+'/savePermissionAndShare';
	return rxAjax.postJson(url,parameter);
}

//获取大屏分享与授权
ScreenViewManageApi.getPermissionAndShare =function(alias) {
	let url=ScreenViewManageApi.baseUrl+'/getPermissionAndShare?alias='+alias;
	return rxAjax.get(url);
}

// //分享大屏
// ScreenViewManageApi.screenShare =function(parameter) {
// 	let url='/api-screen/screen/core/screenShareRecord/screenShare';
// 	return rxAjax.postJson(url,parameter);
// }


export default ScreenViewManageApi;

